package com.geely.design.pattern.creational.simplfactory;

/**
 * 将业务逻辑抽离出调用者,当用新的业务出现时
 * 只需更改视频工厂就好了,调用者无需知道业务逻辑,不受新增
 * 业务影响,   ---简单工厂
 */
public class VideoFactory {

    /**
     * 实现只传入对应的类就能实现业务逻辑,无需更改工厂方法
     * mysql Driver
     * LoggerFactory
     * @param c
     * @return
     */
    public Video getVideo(Class c){
        Video video = null;
        try {
            video = (Video) Class.forName(c.getName()).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return video;
    }

    /**
     * 新增业务只需填对应业务逻辑判断就能实现业务场景
     * @param type
     * @return
     */
    public Video getVideo(String type){
        if("java".equalsIgnoreCase(type)){
            return new JavaVideo();
        }else if("python".equalsIgnoreCase(type)){
            return new PyrhonVideo();
        }
        return null;
    }
}
